package keyboard;

import java.util.HashMap;
import java.util.HashSet;

public class GroupCostCalculatorUsingFingertip extends GroupCostCalculator{
	/*float[][] sizeCost = {
			{},
			{0f, 1.732275f, 0.874231f, 0.841463f, 0.905258f, 0.811453f, 0.797088f, 0.786931f, 0.802444f, 0.850775f, 0.805220f},
			{0f, 1.181598f, 0.670635f, 0.621711f, 0.602394f, 0.571606f, 0.540294f, 0.521975f, 0.531081f, 0.526450f, 0.519300f},
			{0f, 1.102231f, 0.566475f, 0.550513f, 0.547481f, 0.577294f, 0.544981f, 0.521525f, 0.501377f, 0.505244f, 0.530053f}
	};*/
	
	public GroupCostCalculatorUsingFingertip(Keyboard keyboard, HashSet<Character> keysGroup, HashMap<Character, Float> keysValue, Position lastPosition) {
		super(keyboard, keysGroup, keysValue, lastPosition);
	}
	
	@Override
	public float GetTheCostOfPriority(int priority) {
		Position nextSize = keyboard.GetNextSize();
		Position selectorSize = keyboard.GetSelectorSize();
		//float cost = sizeCost[(int)selectorSize.r][(int)selectorSize.c];
		//cost += sizeCost[(int)nextSize.r][(int)nextSize.c] * ((priority - 1) / 4);
		float cost = calnCostBySize(selectorSize);
		cost += calnCostBySize(nextSize) * ((priority - 1) / 4);
		return cost;
	}

	@Override
	public float GetExpectedCost() {
		Position codeSize = keyboard.GetGroupSize(keysGroup);
		float codeCost = calnCostBySize(codeSize);
		
		float groupValue = keyboard.CalnGroupValue(keysGroup, keysValue);
		return codeCost * groupValue + GetSelectingCost();
	}

	public static float calnCostBySize(Position size) {
		//return (float)(Math.log((Keyboard.layout.length * Keyboard.layout[0].length) / (size.r * size.c)) / Math.log(2f)) / 2f; //0
		return (float)(Math.sqrt(Keyboard.layout.length * Keyboard.layout[0].length) - Math.sqrt(size.r * size.c)); //1
		//return (float)-(Math.log((size.r * size.c)) / Math.log(2f)) / 2f; //2
		//return 30f - size.r * size.c; //3
	}
}
